<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数案例</title>
    <script>
        // 1.利用函数求任意两个数的和
        /* function getsum(n, m) {
            return(n+m);
        }
        console.log(getsum(10, 20); */

        // 2.利用函数求任意两个数之间的和
        /* function getsum(n, m) {
            var sum = 0;
            for (var i = n; i < m; i++) {
                sum += i;
            }
            return sum;
        }
        console.log(getsum(2, 6)); */

        // 3.利用函数求任意两个数的最大值
        /*  function max(num1, num2) {
             var result = num1 > num2 ? num1 : num2;
             return result;
         }
         console.log(max(2, 3)); */

        // 4.求任意数组中的最大值
        var arr = [5, 2, 99, 101, 67, 77];

        function getMax(num) {
            for (var i = 0; i < arr.length; i++) {
                for (var j = i + 1; j < arr.length; j++) {
                    var temp;
                    if (arr[i] < arr[j]) {
                        temp = arr[i];
                        arr[i] = arr[j];
                        arr[j] = temp;
                    }
                }
            }
            return arr[0];
        }
        console.log(getMax(arr));
    </script>
</head>

<body>

</body>

</html>